﻿using BaoVeThanhDia.Buttons;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace BaoVeThanhDia.MapAndUpgrade
{
    class MapInterface
    {
        List<ItemMap> itemmaps;
        FileThanh file;
        List<Button> boneMap;
        public MapInterface()
        {
            file = new FileThanh();
            itemmaps = new List<ItemMap>();
            for (int i = 0; i < 60; i++)
            {
                itemmaps.Add(new ItemMap(i, FileThanh.isOpens[i], FileThanh.Stars[i]));
            }
            boneMap = new List<Button>();
            boneMap.Add(new Button("", "images/mapandupgrade/mapdongco", new Vector2(20, 240), Vector2.Zero, new Vector2(300, 186), 0.7f));
            boneMap.Add(new Button("", "images/mapandupgrade/mapcaonguyen", new Vector2(140, 340), Vector2.Zero, new Vector2(300, 105), 0.9f));
            boneMap.Add(new Button("", "images/mapandupgrade/maplaudai", new Vector2(785, 380), Vector2.Zero, new Vector2(300, 200), 0.7f));
            boneMap.Add(new Button("", "images/mapandupgrade/mapnuilua", new Vector2(800, 190), Vector2.Zero, new Vector2(300, 210), 0.7f));
            boneMap.Add(new Button("", "images/mapandupgrade/mapnuidoc", new Vector2(460, 230), Vector2.Zero, new Vector2(300, 179), 0.7f));
            boneMap.Add(new Button("", "images/mapandupgrade/mapnuibang", new Vector2(600, 50), Vector2.Zero, new Vector2(300, 174), 0.7f));
        }
        public void Load(ContentManager contentManager)
        {
            foreach (ItemMap item in itemmaps)
            {
                item.Load(contentManager);
            }
            foreach (Button bone in boneMap)
            {
                bone.Load(contentManager);
            }
        }
        public void Draw(SpriteBatch spriteBatch, Vector2 Dolech, float scale)
        {
            foreach (Button bone in boneMap)
            {
                bone.Draw(spriteBatch, Dolech, bone.getScale() * scale);
            }
            foreach (ItemMap item in itemmaps)
            {
                item.Draw(spriteBatch, Dolech, scale);
            }
        }
        public int isTouch(Vector2 touch, Vector2 Dolech, float mscale, bool isclear = false)
        {
            int temp = -1;
            foreach (ItemMap item in itemmaps)
            {
                if (item.isTouch(touch, Dolech, mscale))
                {
                    temp = item.getIndex();
                    if (isclear) item.setTouch(false);
                    break;
                }
            }
            return temp;
        }
    }
}
